package cn.janescott.framework.core.exception;

import cn.janescott.framework.core.json.deserializer.MyExceptionDeserializer;
import cn.janescott.framework.core.json.serializer.MyExceptionSerializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * 自定义异常
 *
 * @author scott
 * @date 2019/2/12
 */
@JsonSerialize(using = MyExceptionSerializer.class)
@JsonDeserialize(using = MyExceptionDeserializer.class)
public class MyException extends RuntimeException {

    private String errorCode;

    public MyException() {
        super();
    }

    public MyException(String message) {
        super(message);
    }

    public MyException(Throwable cause) {
        super(cause);
    }

    public MyException(String message, Throwable cause) {
        super(message, cause);
    }

    public MyException(String code, String message) {
        super(message);
        this.errorCode = code;
    }

    public MyException(String code, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = code;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    @Override
    public String toString() {
        return getClassName() + "{" +
                "errorCode='" + errorCode + '\'' +
                ", errorMessage='" + getMessage() + '\'' +
                "}";
    }

    private String getClassName() {
        return this.getClass().getSimpleName();
    }
}
